﻿using System;
using System.Collections.Generic;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using YJKStairs.HYElevator.Manage;

namespace YJKStairs
{
	[Transaction(TransactionMode.Manual)]
	[Regeneration(RegenerationOption.Manual)]
	public class CmdDeleteElevator : IExternalCommand
	{
		Result IExternalCommand.Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
		{
			UIDocument activeUIDocument = commandData.Application.ActiveUIDocument;
			Document document = activeUIDocument.Document;
			HideWarningKit @object = new HideWarningKit("删除电梯");
			commandData.Application.Application.FailuresProcessing += @object.OnFailuresProcessing;
			DeleteElevatorCls deleteElevatorCls = new DeleteElevatorCls(activeUIDocument);
			Result result;
			try
			{
				IList<Element> list;
				do
				{
					list = activeUIDocument.Selection.PickElementsByRectangle(new ElevatorSelFilter(), "选择需要删除的电梯:");
				}
				while (list.Count == 0 || deleteElevatorCls.Run(list as List<Element>));
				result = Autodesk.Revit.UI.Result.Failed;
			}
			catch (Exception)
			{
				result = Autodesk.Revit.UI.Result.Succeeded;
			}
			return result;
		}
	}
}
